<?php 

/**
 * NOTICE OF LICENSE
 *
 * THIS SOURCE FILE IS PART OF EVEBIT'S PRIVATE PROJECT.
 * 
 * DO NOT USE THIS FILE IN OTHER PLACE.
 *
 * @package     App_User
 * @subpackage  View
 * @author      Cheng Wei <berlios.o@gmail.com>
 * @version     $$Id: profile.phtml 20 2010-12-18 09:35:07Z cheng.wei $$
 */

$this->headTitle($this->__('Profile'));
$this->placeholder('page_class')->append('profile-page');
/* @var $user User_Model_Entity_User */
$user = $this->data;
/* @var $helper Evebit_View_Helper_Profile */
$helper = $this->profile($user->getId());

$this->headLink()->appendStylesheet($this->baseUrl("media/css/profile.css"));

$language = Evebit_Application_Session::getInstance()->getLocale();
$language = substr($language, 0, 2);

$currentUser = $this->getUser();

$userEmail = $user->getEmail();

?>	
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&language=<?php echo $language?>"></script>
<script type="text/javascript" src ="http://www.google.com/jsapi"></script>
<div class="profile">
	<div class="profile-top-button">		
		<?php if($this->hasLogin() && ($currentUser->getId() != $user->getId())):?>
		
		<?php if (!$currentUser->hasFriend($user)):?>
			<button type="button" class="form-button button"
					onclick="javascript:poll.inviteFriend('<?php echo $user->getId() ?>','friend','inviteFriend')">
				<span><span><?php echo $this->__(" + Add as friend")?></span></span>
			</button>
			
			<?php if (!$currentUser->hasFollowing($user)):?>
			<button type="button" class="form-button button"
				onclick="poll.following('<?php echo $user->getId() ?>', 'user')">
				<span><span><?php echo $this->__("Follow")?></span></span>
			</button>
			<?php else:?>
			<button type="button" class="form-button button follow"
				onclick="poll.deleteFollowingUser('<?php echo $user->getId() ?>')">
				<span><span><?php echo $this->__("Stop following")?></span></span>
			</button>
			<?php endif;?>
			
		<?php else:?>
		<button type="button" class="form-button button follow"
			onclick="poll.deleteFriend('<?php echo $user->getId() ?>')">
			<span><span><?php echo $this->__("Remove friend")?></span></span>
		</button>
		<?php endif;?>
		
		<?php endif; ?>
		<div class="clear"></div>
	</div>
	<div class="profile-content">
		<dl class="clearfix" >
			<dt>
				<label for="data-firstname">
					<span><?php echo $this->__("Poll information:")?></span>					
				</label>
			</dt>
			<dd>
				<ul>
					<li><?php printf("Has created %d polls",  $helper->getPollCount() )?></li>
					<li><?php printf("Has voted %d polls", $helper->getVotedCount() )?></li>
					<li>
						<?php echo $this->__('Most popular poll')?>:
						<?php $poll = $helper->getMostPopulerPoll()?>
						<?php if($poll):?>
							<?php echo $this->getLink($poll,
									array("content"=>'<span class="profile-poll-name">'.$poll->getName().'</span>')
								) ?>
							<?php printf($this->__('has received %d votes'), $poll->getTotalVoted())?>
						<?php endif;?>
					</li>
					<li><?php printf($this->__("Has commented %d times on polls"), $helper->getCommentsCount() )?></li>
					<li>
						<?php printf($this->__('Views polls in %s'), 
							implode(', ', $helper->getPollLanguages()))?>
					</li>
				</ul> 
			</dd>
		</dl>
		<dl class="clearfix" >
			<dt>
				<label for="data-firstname">
					<span><?php echo $this->__("Contact information:")?></span>					
				</label>
			</dt>
			<dd>
				<ul>
					<?php $address = $user->getAddress() ?>
					<?php if ($user->checkPrivacy($currentUser, 'privacy_email')):?>
					<li><?php echo $this->__("E-mail address: "); printf("<a href=\"mailto:%s\">%s</a>", $userEmail, $userEmail); ?></li>
					<?php endif;?>
					<li><?php printf($this->__("Country: %s"), Zend_Locale::getTranslation($address->getCountry(), 'country'))?></li>
					<?php if ($user->checkPrivacy($currentUser, 'privacy_address')):?>
					<li>
						<?php
							$line = array();
							if ($address->getZipCode()) {
								$line[] = $address->getZipCode(); 
							} 
                                                        if ($address->getCity()) {
								$line[] = $address->getCity(); 
							} 
							
							//$line[] = Zend_Locale::getTranslation($address->getCountry(), 'country');
						?>
						<?php printf($this->__("Address: %s"), implode(', ',$line))?>
					</li>
					<?php endif;?>
					<?php if ($user->checkPrivacy($currentUser, 'privacy_phonenumber')):?>
					<li><?php printf($this->__("Phone number: %s"), $user->getPhonenumber())?></li>
					<?php endif;?>

					<li><?php printf($this->__("PollParrots: <a target=\"_parent\" href=\"/%s\">http://www.pollparrots.com/%s</a>"), $user->getUsername(), $user->getUsername())?></li>
				</ul>
				
				<div class="profile-map">
				<?php
					$zoom = $address->getZoom() ? $address->getZoom() : 1;
					$latitude = $address->getCx() ? $address->getCx() : 55.72;
					$longitude = $address->getCy() ? $address->getCy() : 9.50;
				?>
    				<div id="map_canvas" style="width:500px; height:300px;"></div>
    				<script>
    				var map = new google.maps.Map($('map_canvas'), {
    			    	zoom: 		<?php echo $zoom?>,
    		    		center: 	new google.maps.LatLng(<?php echo $latitude?>, <?php echo $longitude?>),
    		        	mapTypeId: 	google.maps.MapTypeId.ROADMAP,
    		        	mapTypeControl: false,
    		        	scaleControl: false,
    		        	navigationControl: false
    		        }); 
    				<?php if($address->getLatitude() || $address->getLongitude()): ?>
    		        var point  = new google.maps.LatLng(
    		        	<?php echo $address->getLatitude() ?>,<?php echo $address->getLongitude()?>);        
    		        var marker = new google.maps.Marker({position:point,map: map});
    		        <?php endif;?>
    				</script>
				</div>				
			</dd>
		</dl>
		<dl class="clearfix" >
			<dt>
				<label for="data-firstname">
					<span><?php echo $this->__("Personal information:")?></span>					
				</label>
			</dt>
			<dd>
				<ul>
					<li><?php printf($this->__("Gender: %s"), $user->getGender())?></li>
					<?php if ($user->checkPrivacy($currentUser, 'privacy_birthday')):?>
					<li><?php printf($this->__("Birthday: %s"), $user->getBirthday()->get(Zend_Date::DATE_LONG))?></li>
					<?php endif;?>
					<?php if ($user->checkPrivacy($currentUser, 'privacy_relationship')):?>
					<li><?php echo $user->getRelationship()?></li>
					<?php endif;?>
					<?php if ($user->checkPrivacy($currentUser, 'privacy_webpage')):?>
					<li><?php echo $this->__('Personal webpage:')?></li>
					<?php if ($link = $user->getData('link')):?>
					<li><a href="<?php echo $link?>" target="_blank"><?php echo $link?></a></li>
					<?php endif;?>
					<?php for($i=2;$i<=5;$i++):?>
						<?php if ($link = $user->getData("link$i")):?>
						<li><a href="<?php echo $link?>" target="_blank"><?php echo $link?></a></li>
						<?php endif;?>
					<?php endfor;?>
					<?php endif;?>
					<?php if ($user->checkPrivacy($currentUser, 'privacy_shoesize')):?>
					<li><?php printf($this->__('Shoesize: %s'), $user->getShoesize())?></li>
					<li class="seperator"></li>
					<?php endif;?>
					<?php if ($user->checkPrivacy($currentUser, 'privacy_yourself')):?>
					<li><?php echo $this->__('About myself:')?></li>
					<li><?php echo $user->getPersonalInformation()?></li>
					<li class="seperator"></li>
					<?php endif;?>
					<?php if ($user->checkPrivacy($currentUser, 'privacy_political')):?>
					<li><?php printf($this->__('Political view: %s'), $user->getPoliticalViews())?></li>
					<li class="seperator"></li>
					<li><?php echo $user->getMorePoliticalViews()?></li>
					<li class="seperator"></li>
					<?php endif;?>
					<?php if ($user->checkPrivacy($currentUser, 'privacy_religion')):?>
					<li><?php printf($this->__('Religion: %s'), $user->getReligiousViews())?></li>
					<li class="seperator"></li>
					<li><?php echo $user->getMoreReligiousViews()?></li>
					<?php endif;?>
				</ul>
			</dd>
		</dl>
		<dl class="clearfix" >
			<dt>
				<label for="data-firstname">
					<span><?php echo $this->__("Work and education:	")?></span>					
				</label>
			</dt>
			<dd>
				<ul>
					<?php if ($user->checkPrivacy($currentUser, 'privacy_education')):?>
					<li><?php printf($this->__('Education: %s'), $user->getEducation())?></li>
					<li class="seperator"></li>
					<li><?php echo $this->__('Institutions i attended:')?></li>
					<?php foreach ($user->getInstitutions() as $institution):?>
						<li><?php echo $institution['institution']?></li>
						<li><?php echo $institution['from']->get(Zend_Date::DATE_LONG)?>
							 - <?php echo $institution['to']->get(Zend_Date::DATE_LONG)?></li>
					<?php endforeach;?>
					<li class="seperator"></li>
					<?php endif;?>
					<?php if ($user->checkPrivacy($currentUser, 'privacy_employer')):?>
					<li><?php printf($this->__('Current position: %s'), $user->getCurrentPosition())?></li>
					<li class="seperator"></li>
					<li><?php echo $this->__('Current employer:')?></li>
					<li><?php echo $user->getCurrentEmployer()?></li>
					<?php if ($user->getCurrentEmployerUrl()):?>
					<li>
						<a href="<?php echo $user->getCurrentEmployerUrl()?>" target="_blank">
							<?php echo $user->getCurrentEmployerUrl()?>
						</a>
					</li>
					<?php endif;?>
					<li class="seperator"></li>
					<li><?php echo $this->__('Past employers:')?></li>
					<?php foreach ($user->getFormers() as $former):?>
						<li><?php echo $former['employee']?></li>
						<li><?php echo $former['from']->get(Zend_Date::DATE_LONG)?>
							 - <?php echo $former['to']->get(Zend_Date::DATE_LONG)?></li>
						<li class="seperator"></li>
					<?php endforeach;?>
					<?php endif;?>
					<?php if ($user->checkPrivacy($currentUser, 'privacy_work_experience')):?>
					<li><?php echo $this->__('Work experience:')?></li>
					<li><?php echo $user->getWorkExperience()?></li>
					<?php endif;?>
				</ul>
			</dd>
		</dl>	
		
	</div>
	
</div>